#region File Description
//-----------------------------------------------------------------------------
// InputState.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
using System;
//using Microsoft.Xna.Framework.Input.Touch;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace ForgottenTalez.InputManager
{
   
    public class Input: GameComponent
    {
        #region Fields
        KeyboardState currentKeyboardState = Keyboard.GetState();
        KeyboardState previousKeyboardState = Keyboard.GetState();
        #endregion

        #region Static Fields
        private static int createFailCount = 0;//Net vir debugging
        private static Input instance;
        #endregion

        #region <<<Constructors>>>
        private Input(Game game) : base(game) { }
        #endregion

        #region Initialization
        public static Input InitializeAndGetInstance(Game game)
        {
            if (instance == null)
            {
                instance = new Input(game);
            }
            else
            { 
                createFailCount += 1; 
                Debug.WriteLine("InputManager.Input: unwanted attempted Create nr" + createFailCount, "Unwanted Usage");
            }
            return instance;
        }
        #endregion

        #region Properties
        private bool isInitialized
         {
             get { return instance != null; }
         }
        #endregion

        #region Public Methods
        public static bool isKeyDown(Keys key)
        {
            if(instance != null)
                return instance.currentKeyboardState.IsKeyDown(key);

            throw new Exception("Input has not been initialized, call Input(Game game) first");
        }

        public static bool isKeyUp(Keys key)
        {
            return instance.currentKeyboardState.IsKeyUp(key);

            throw new Exception("Input has not been initialized, call Input(Game game) first");
        }

        public static bool wasKeyPressed(Keys key)
        {
            if (instance != null)
            {
                return instance.previousKeyboardState.IsKeyDown(key) && isKeyUp(key);
            }

            throw new Exception("Input has not been initialized, call Input(Game game) first");
        }

        public static bool IsTouching()
        {
            if (instance != null)
            {
                /* Figure uit om gestures te gebruik en implement die method*/
                return false;
            }
            throw new Exception("Input has not been initialized, call Input(Game game) first");
        }


        #endregion

        #region Update
        public override void Update(GameTime gameTime)
        {
            if (instance != null)
            {
                previousKeyboardState = currentKeyboardState;
                currentKeyboardState = Keyboard.GetState();
            }
            base.Update(gameTime);
         
        }
        #endregion
    }
}
